package amsStore;

import item.PurchaseItem;
import item.ShoppingCartItem;

import java.sql.Date;
import java.util.List;

public class Receipt {
	private int 				receiptId;
	private Date 				purchaseDate;
	private List<PurchaseItem> 	purchaseItems;
	private boolean 			isCreditPurchase;
	private String				cardLastFiveDigits;
	private float				totalPurchaseAmount;
	
	
	public Receipt(int receiptId, Date date, List<PurchaseItem> purchaseItems, boolean isCreditPurchase, String cardLastFiveDigits) {
		this.receiptId = receiptId;
		this.purchaseDate = date;
		this.purchaseItems = purchaseItems;
		this.isCreditPurchase = isCreditPurchase;
		this.cardLastFiveDigits = cardLastFiveDigits;
		
		for(PurchaseItem curPurchaseItem : this.purchaseItems)
		{
			this.totalPurchaseAmount += curPurchaseItem.getSellPrice() * curPurchaseItem.getQuantity();
		}
	}
	
	public Receipt(int receiptId, Date date, boolean isCreditPurchase, String cardLastFiveDigits, Bill bill)
	{
		this.receiptId = receiptId;
		this.purchaseDate = date;
		this.isCreditPurchase = isCreditPurchase;
		this.cardLastFiveDigits = cardLastFiveDigits;
		
		List<ShoppingCartItem> billItems = bill.getBillItems();
		for(ShoppingCartItem billItem : billItems)
		{
			this.purchaseItems.add(new PurchaseItem(receiptId, billItem));
		}
	}

	public int getReceiptId() {
		return receiptId;
	}

	public Date getDate() {
		return purchaseDate;
	}

	public List<PurchaseItem> getItems() {
		return purchaseItems;
	}

	public boolean isCreditPurchase() {
		return isCreditPurchase;
	}

	public String getCardLastFiveDigits() {
		return cardLastFiveDigits;
	}	
	
	public float getTotalPurchaseAmount() {
		return totalPurchaseAmount;
	}
	
	
}
